import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/utils/util.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    SubjectState state, Dispatch dispatch, ViewService viewService) {
  return Card(
    color: Colors.white,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(0),
    ),
    elevation: 2.0,
    margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
    child: ListTile(
        onTap: () => dispatch(SubjectActionCreator.onClick()),
        leading: Container(
            width: 38,
            height: 44,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.blue,
            ),
            padding: EdgeInsets.all(11.0),
            child: Text(
              '题',
              style: TextStyle(color: Colors.white),
            )),
        title: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            SizedBox(height: 8),
            Text(
                state.title == null || state.title.isEmpty
                    ? '题目自拟'
                    : state.title,
                style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
            SizedBox(height: 8),
            Text(
              Util.plainText(state.demand, defaultText: '无要求', maxLength: 50),
              maxLines: 2,
              style: TextStyle(fontSize: 14),
            ),
            SizedBox(height: 8),
            Divider(height: 1),
            SizedBox(height: 8),
            Text(state.ctime, style: TextStyle(fontSize: 12, color: Colors.grey)),
          ],
        )),
  );
}
